/**
 * Copyright (c) 2010 CWI Amsterdam and others. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    CWI Amsterdam - initial API and implementation
 */
package nl.cwi.arne.ui.parts;

import nl.cwi.arne.diagram.part.ArneDiagramEditor;
import nl.cwi.arne.util.NetworkActivationBuffer;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.swt.widgets.Display;

/**
 * @author Christian Krause
 */
public class NetworkActivationBufferWithAutoSave extends NetworkActivationBuffer {
	
	// Default serial id:
	private static final long serialVersionUID = 1L;

	// Editor:
	private DiagramEditor editor;

	/**
	 * Default constructor.
	 * @param editor Arne duiagram editor.
	 */
	public NetworkActivationBufferWithAutoSave(ArneDiagramEditor editor) {
		super(editor.getNetwork());
		setEditingDomain(editor.getEditingDomain());
		this.editor = editor;
	}
	
	/*
	 * (non-Javadoc)
	 * @see nl.cwi.arne.util.NetworkActivationBuffer#commit()
	 */
	@Override
	public boolean commit() {
		if (super.commit()) {
			Display.getDefault().asyncExec(new Runnable() {
				public void run() {
					editor.doSave(new NullProgressMonitor());
				}
			});
			return true;
		}
		return false;
	}

}
